package controller;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import util.LoginListener;
import util.Server;
import view.ChessPanel;
import view.GridPanel;
import view.InfoPanel;
import view.LoginPanel;

public class Controll {
	private LoginPanel loginPanel;
	private ChessPanel chessPanel;
	private GridPanel gridPanel;
	private InfoPanel infoPanel;
	private Socket socket;

	public Controll(LoginPanel loginPanel, ChessPanel chessPanel, GridPanel gridPanel, InfoPanel infoPanel) {
		this.loginPanel = loginPanel;
		this.chessPanel = chessPanel;
		this.gridPanel = gridPanel;
		this.infoPanel = infoPanel;
		
		loginPanel.setLoginListener(new LoginListener() {
			
			@Override
			public void setSocket(Socket socket) {
				Controll.this.socket=socket;
				System.out.println("客户端连接成功");
			}
		});
	}
	
	public void setSocket() {
		ServerSocket server=Server.start(loginPanel);
		if(server!=null){
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					try {
						server.accept();
						System.out.println("服务端连接成功");
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}).start();
		}
	}
	
	
}
